#/bin/sh!

cat > /etc/yum.repos.d/ceph.repo << EOF
[Ceph]
name=Ceph packages for $basearch
gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc
enabled=1
baseurl=http://ceph.com/rpm-firefly/el6/\$basearch
priority=1
gpgcheck=1
type=rpm-md

[ceph-source]
name=Ceph source packages
gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc
enabled=1
baseurl=http://ceph.com/rpm-firefly/el6/SRPMS
priority=1
gpgcheck=1
type=rpm-md

[Ceph-noarch]
name=Ceph noarch packages
gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc
enabled=1
baseurl=http://ceph.com/rpm-firefly/el6/noarch
priority=1
gpgcheck=1
type=rpm-md


[ceph-extras]
name=Ceph Extras
baseurl=http://ceph.com/packages/ceph-extras/rpm/centos6/\$basearch
enabled=1
priority=2
gpgcheck=1
type=rpm-md
gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc

[ceph-qemu-source]
name=Ceph Extras Sources
baseurl=http://ceph.com/packages/ceph-extras/rpm/centos6/SRPMS
enabled=1
priority=2
gpgcheck=1
type=rpm-md
gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc
EOF

yum -y update
yum -y install librados2 librbd1 libcephfs1 ceph

cp -r  /net/192.168.200.254/scratch/scripts/ceph/  /etc/
#cp  /net/192.168.200.254/scratch/scripts/ceph/ceph.client.cinder.keyring /etc/ceph/
#cp  /net/192.168.200.254/scratch/scripts/ceph/ceph.client.glance.keyring /etc/ceph/
chown -r cinder:cinder /etc/ceph/
export user_name=admin
#CEPH_ARGS="--id ${user_name}"
#key=`ceph auth get-key client.cinder`
key=`grep key   /etc/ceph/ceph.client.${user_name}.keyring  |awk '{print $3}'`

fileenv=`mktemp`

service01="openstack-cinder-backup openstack-glance-api openstack-cinder-volume"


cat > $fileenv << EOF
DEFAULT volume_driver cinder.volume.drivers.rbd.RBDDriver
DEFAULT rbd_pool volumes
DEFAULT rbd_user ${user_name}
DEFAULT rbd_secret_uuid $key
DEFAULT glance_api_version 2
DEFAULT rbd_ceph_conf /etc/ceph/ceph.conf
DEFAULT rbd_flatten_volume_from_snapshot false
DEFAULT rbd_max_clone_depth 5
DEFAULT backup_driver cinder.backup.drivers.ceph
DEFAULT backup_ceph_user cinder-backup
DEFAULT backup_ceph_pool backups
DEFAULT backup_ceph_chunk_size 134217728
DEFAULT backup_ceph_stripe_unit 0
DEFAULT backup_ceph_stripe_count 0
DEFAULT restore_discard_excess_bytes true
EOF

cat $fileenv| while read line; do
	openstack-config --set /etc/cinder/cinder.conf $line
done
rm -f  $fileenv;



cat > $fileenv << EOF
DEFAULT glance_host
DEFAULT volume_group
EOF

cat $fileenv| while read line; do
        openstack-config --del /etc/cinder/cinder.conf $line
done
rm -f  $fileenv;


cat > $fileenv << EOF
DEFAULT default_store rbd
DEFAULT rbd_store_user ${user_name}
DEFAULT rbd_store_pool images
DEFAULT rbd_store_ceph_conf /etc/ceph/ceph.conf
client.images keyring /etc/ceph/ceph.client.${user_name}.keyring
EOF

cat $fileenv| while read line; do
        openstack-config --set /etc/glance/glance-api.conf  $line
done
rm -f  $fileenv;

for serv in $service01; do
        service $serv restart;
        chkconfig $serv on;
done








